#include #include using std::cin; using std::cout; using std::endl; const int LIST_SIZE = 500; void swap(int& x, int& y) { int temp = x; x = y; y = temp; } void main() { srand((int)time(NULL)); int A[LIST_SIZE]; for(int i =0; i < LIST_SIZE; i++) { A[i] = rand() % 500; } int indexOfLargest = 0; for(int i = 0; i < LIST_SIZE-1; i++) { indexOfLargest = 0; //finds the index of the largest value //in the unsorted part of the array for(int j = 1; j < LIST_SIZE - i; j++) { if(A[j] < A[indexOfLargest]) { indexOfLargest = j; } } //swap the value at indexOfLargest with A[LIST_SIZE-i-1] swap(A[indexOfLargest], A[LIST_SIZE-i-1]); } for(int i= 0; i < LIST_SIZE; i++) { cout << A[i] << endl; } }